<template>
    <div class="themes">
        <!--统计-->
        <statistics v-if="interactMsg.interactType == 1"
                    :interactProp="interactMsg"
                    @recordList="recordList"
                    @joinTHeme="joinTHeme"></statistics>
        <!--对垒-->
        <stand-facing v-else-if="interactMsg.interactType == 2"
                      :interactProp="interactMsg"
                      @recordList="recordList"
                      @joinTHeme="joinTHeme"></stand-facing>
        <!--投票-->
        <vote v-else-if="interactMsg.interactType == 3"
              :interactProp="interactMsg"
              @recordList="recordList"
              @joinTHeme="joinTHeme"></vote>
        <!--有奖问答 -->
        <feedback-answer v-else-if="interactMsg.interactType == 4"
                         :interactProp="interactMsg"
                         @recordList="recordList"
                         @joinTHeme="joinTHeme"></feedback-answer>

    </div>
</template>

<script>
    export default {
        name: "Themes",
        props:{
            interactProp:Object
        },
        data(){
            return{
                interactMsg:{
                    isSlef:false,//是否为自己
                    interactId:0,//互动id,
                    interactType:0,//互动类型(0, "null"),(1, "征集/统计"),(2, "对垒"),(3, "投票"),(4, "有奖问答");
                }
            }
        },
        mounted(){
            this.interactMsg = Object.assign({},this.interactMsg,this.interactProp);
            // this.initInteract();
        },
        methods:{
           joinTHeme(optionId){
               //interactId:互动id,optionId:点击的互动选项id
               let url = `${this.NW_API_API_LOCALE_VERSION}/interact/${this.userId}/join/interact/${this.interactMsg.interactId}/${optionId}`;
               this.xurl.post(url).then((data)=>{
                    if(data.success){
                        console.log("投票成功");
                    }else if(data.errMsg){
                        console.log(data.errMsg);
                    }else{
                        console.log("投票失败");
                    }
               })
           },
            recordList(optionId,interactId){
                /*TODO 这里没做完，先不往这边拉取数据*/
                return
                let url = `${this.NW_API_API_LOCALE_VERSION}/interact/${this.userId}/getByOptionId/${this.interactMsg.interactId}/${optionId}?pageSize=10&pageNum=1`;
                this.xurl.get(url).then((data)=>{
                    if(data.success){
                        this.$emit('recordList',data);
                    }else if(data.errMsg){
                        console.log(data.errMsg);
                    }else{
                        console.log("获取参与记录失败");
                    }
                })
            },
            initInteract(){
                let url = `${this.NW_API_API_LOCALE_VERSION}/curUser/${this.userId || 0}/interact/getById/${this.interactMsg.interactId}`;
                this.xurl.get(url).then((data)=>{
                    if(data.success){
                        this.interactMsg = Object.assign({},this.interactMsg,data.result);
                        this.$emit('recordList',data);
                    }else if(data.errMsg){
                        console.log(data.errMsg);
                    }else{
                        console.log("获取参与话题信息失败");
                    }
                })
            }
        },
        components:{
            'stand-facing':()=>import('./StandFacing'),
            'statistics':()=>import('./Statistics'),
            'vote':()=>import('./Vote'),
            'feedback-answer':()=>import('./FeedbackAnswer'),

        },
        watch:{
            interactProp(val){
                this.interactMsg = Object.assign({},this.interactMsg,val);
            }
        }
    }
</script>

<style scoped>
</style>